<?php
use LIBS\DES;
use LIBS\Curl;
require_once '../LIBS/DES.class.php';
require_once '../LIBS/Curl.class.php';
$appkey = '8407631E1980EBD18849ACFBFD3C1A0A';
$secret = '8407631E1980EBD18849ACFBFD3C1A0R';
$cururl='http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
$logpath="http://web.sso.com/login.html?appkey=".$appkey."&return=".urlencode($cururl);
$skey = @$_GET['ticket'];
$user;
if ( @$_COOKIE['user_info'] )
{
    //expires
    $user=   json_decode($_COOKIE['user_info'], true);
    return;
}
else {
    if(empty($skey)){
        header('Location: '.$logpath);
        exit;
    }

    $des = new DES($secret);
    $data = @ $des->encrypt($skey . ';' . time());

    $Curl = new Curl();
    $ret = $Curl->curl_get("http://svc.sso.com/app/services/get_ticket.php?appkey=$appkey&data=$data");

    //echo $ret;
    $ret1 = strval($ret);

    $retobj=json_decode($ret1,true);

    if($retobj["code"]!=0){
        header('Location: '.$logpath);
        exit;
    }
    $user=  $retobj["data"];
    setcookie('user_info', json_encode($user));


}


?>
